🎲 Basic Probability
Probability is the language of uncertainty. In Machine Learning, we almost never say "This image is a cat." Instead, we say "I am 98% sure this image is a cat."
🪙 The Coin Flip
Probability is just counting outcomes. If you flip a fair coin, there are 2 possible outcomes (Heads, Tails).
The probability of Heads is 1 / 2 = 0.5.
🐍 Python Implementation
We can simulate probability in Python by actually flipping a virtual coin thousands of times using random!
import random
def flip_coin():
# Returns True for Heads, False for Tails
return random.random() > 0.5
flips = 10000
heads_count = sum([flip_coin() for _ in range(flips)])
# The probability should converge to roughly 0.50!
print(f"Probability of Heads after {flips} flips: {heads_count / flips}")